package com.hyh.toyshopping.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @version 1.0
 * @BelongsProject:IntelliJ IDEA
 * @BelongsPackage:com.hyh.myshopping.utils
 * @Author:hyhWTX
 * @ClassName:OrderUtils
 * @CreateTime:2022年-12月-12日 16:39
 * @Description: 订单工具类-用于生成订单编号
 */
public class OrderUtils {

    private static Integer initNum = 1;
    private static final Integer MAXNUM =10000;
    /***
     * @Description: 获得订单编号
     * @return String

     */

    public static synchronized  String getOrderId(){
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String nowTime = format.format(new Date());
        String orderId = nowTime+initNum;
        initNum++;
        if(initNum>MAXNUM){
            initNum = 0;
        }
        System.out.println(orderId);
        return orderId;
    }
    public static void main(String[] args) {
        for (int i = 0; i < 1000; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    com.hyh.toyshopping.utils.OrderUtils.getOrderId();
                }
            }).start();

        }
    }
    }
